a tool for shared writing and social publishing
1import { publishToPublication } from "actions/publishToPublication";
2import {
3 getBasePublicationURL,
4 getPublicationURL,
5} from "app/lish/createPub/getPublicationURL";
6import { ActionButton } from "components/ActionBar/ActionButton";
7import { GoBackSmall } from "components/Icons/GoBackSmall";
8import { PublishSmall } from "components/Icons/PublishSmall";
9import { useLeafletPublicationData } from "components/PageSWRDataProvider";
10import { SpeedyLink } from "components/SpeedyLink";
11import { useToaster } from "components/Toast";
12import { DotLoader } from "components/utils/DotLoader";
13import { useParams, useRouter } from "next/navigation";
14import { useState } from "react";
15import { useReplicache } from "src/replicache";
16import { Json } from "supabase/database.types";
17
18export const BackToPubButton = (props: {
19 publication: {
20 identity_did: string;
21 indexed_at: string;
22 name: string;
23 record: Json;
24 uri: string;
25 };
26}) => {
27 return (
28 <SpeedyLink
29 href={`${getBasePublicationURL(props.publication)}/dashboard`}
30 className="hover:no-underline!"
31 >
32 <ActionButton
33 icon={<GoBackSmall className="shrink-0" />}
34 label="To Pub"
35 />
36 </SpeedyLink>
37 );
38};
39
40export const PublishButton = () => {
41 let { data: pub } = useLeafletPublicationData();
42 let params = useParams();
43 let router = useRouter();
44 if (!pub?.doc)
45 return (
46 <ActionButton
47 primary
48 icon={<PublishSmall className="shrink-0" />}
49 label={"Publish!"}
50 onClick={() => {
51 router.push(`/${params.leaflet_id}/publish`);
52 }}
53 />
54 );
55
56 return <UpdateButton />;
57};
58
59const UpdateButton = () => {
60 let [isLoading, setIsLoading] = useState(false);
61 let { data: pub, mutate } = useLeafletPublicationData();
62 let { permission_token, rootEntity } = useReplicache();
63 let toaster = useToaster();
64
65 return (
66 <ActionButton
67 primary
68 icon={<PublishSmall className="shrink-0" />}
69 label={isLoading ? <DotLoader /> : "Update!"}
70 onClick={async () => {
71 if (!pub || !pub.publications) return;
72 setIsLoading(true);
73 let doc = await publishToPublication({
74 root_entity: rootEntity,
75 publication_uri: pub.publications.uri,
76 leaflet_id: permission_token.id,
77 title: pub.title,
78 description: pub.description,
79 });
80 setIsLoading(false);
81 mutate();
82 toaster({
83 content: (
84 <div>
85 {pub.doc ? "Updated! " : "Published! "}
86 <SpeedyLink
87 href={`${getPublicationURL(pub.publications)}/${doc?.rkey}`}
88 >
89 link
90 </SpeedyLink>
91 </div>
92 ),
93 type: "success",
94 });
95 }}
96 />
97 );
98};